# coding: utf-8
from pymongo import MongoClient
from pymongo.database import SystemJS

from zUtils import config

mongodb_dbs_config = config['MongoDB']
# connect=False fix `fork` warning
db_client = MongoClient(host=mongodb_dbs_config['Host'], port=mongodb_dbs_config['Port'], connect=False)
db = db_client[mongodb_dbs_config['Database']]
if 'Auth' in mongodb_dbs_config:
    auth_config = mongodb_dbs_config['Auth']
    source = auth_config['Source'] if 'Source' in auth_config else 'admin'
    db.authenticate(auth_config['Username'], auth_config['Password'], source=source)

mongodb_system_js = SystemJS(db)

# 供外部引用
from zUtils.mongodb.mongodb import MongodbBase
